package com.qianli.user.facade.query.impl.quota;

import com.fqgj.common.api.Response;
import com.qianli.user.application.UserQuotaApplication;
import com.qianli.user.facade.query.quota.UserQuotaQueryServiceFacade;
import com.qianli.user.facade.quota.UserQuotaServiceFacade;
import com.qianli.user.ro.UserStateCode;
import com.qianli.user.ro.query.UserQuotaQueryRO;
import com.qianli.user.ro.quota.UserQuotaRO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * name:用户额度查询
 * auth:ting.li@qianli-inc.com
 * date:2018/1/9 16:35
 * version: v1.0.0
 **/
@Service("userQuotaQueryServiceFacade")
public class UserQuotaQueryServiceFacadeImpl implements UserQuotaQueryServiceFacade {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserQuotaServiceFacade.class);

    @Autowired
    private UserQuotaApplication userQuotaApplication;

    /**
     * 获取额度
     * @param queryRO
     * @return
     */
    @Override
    public Response<UserQuotaRO> getQuota(UserQuotaQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserQuotaQueryServiceFacade.getQuota param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()|| null != queryRO.getBiz()){
            LOGGER.info("UserQuotaQueryServiceFacade.getQuota param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserQuotaQueryServiceFacade.getQuota param userCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }
        if(null == queryRO.getCategoryCode()){
            LOGGER.info("UserQuotaQueryServiceFacade.getQuota param categoryCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"categoryCode can not be null");
        }
        UserQuotaRO userQuotaRO = userQuotaApplication.load(queryRO.getUserCode(),queryRO.getCategoryCode());
        return Response.ok(userQuotaRO);
    }

    /**
     * 查询所有额度
     * @param queryRO
     * @return
     */
    @Override
    public Response<List<UserQuotaRO>> queryAllQuotaList(UserQuotaQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserQuotaQueryServiceFacade.queryAllQuotaList param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()|| null != queryRO.getBiz()){
            LOGGER.info("UserQuotaQueryServiceFacade.queryAllQuotaList param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserQuotaQueryServiceFacade.queryAllQuotaList param userCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }

        List<UserQuotaRO> userQuotaROs = userQuotaApplication.load(queryRO.getUserCode());
        return Response.ok(userQuotaROs);
    }
}
